package com.bgs.service.impl;

import com.bgs.pojo.Caozuo;
import org.apache.commons.lang3.BooleanUtils;
import com.bgs.mapper.ResumeMapper;
import com.bgs.pojo.Resume;
import com.bgs.service.jianliService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class jianliServiceImpl implements jianliService {
    @Autowired
    private ResumeMapper mapper;
    @Override
    public List<Resume> findAll() {
        return mapper.findAll();
    }



    @Override
    public Boolean tongguo(Integer status, Integer rid) {
        status++;
        return mapper.tonggo(status,rid);
    }

    @Override
    public Boolean taotai(Integer rid,String remarks,String reason,Boolean rencai) {
            int rencai1 = BooleanUtils.toInteger(rencai);
        return mapper.taotai(rid,remarks,reason,rencai1);
    }

    @Override
    public Boolean update(Resume resume) {

        return mapper.update(resume);
    }

    @Override
    public Boolean delete( Integer rid) {
        return mapper.delete(rid);
    }

    @Override
    public List<Resume> findById(Integer rid) {
        return mapper.findById(rid);
    }

    @Override
    public int find() {
        return mapper.find();
    }

    @Override
    public Boolean tian(Resume resume) {
        return mapper.tian(resume);
    }

    @Override
    public Boolean caozuo(Resume resume) {

        ArrayList<String> ids = new ArrayList<>();
        ArrayList<String> xziduan1 = new ArrayList<>();
        if(!resume.getPosition().equals("")){
            xziduan1.add("申请职位");
            ids.add(resume.getPosition());
            System.out.println("1");
        }
        if(!resume.getSource().equals("")){
            xziduan1.add("简历来源");
            ids.add(String.valueOf(resume.getSource()));
            System.out.println("2");
        }
        if(resume.getStatus() !=null){
            xziduan1.add("候选人状态");
            ids.add(String.valueOf(resume.getStatus()));
            System.out.println("2");
        }
        if(!resume.getEvaluation().equals("")){
            xziduan1.add("自我评价");
            ids.add(resume.getEvaluation());
            System.out.println("1");
        }
        if(!resume.getRname().equals("")){
            xziduan1.add("姓名");
            ids.add(resume.getRname());
            System.out.println("1");
        }
        if(!resume.getRphone().equals("")){
            xziduan1.add("手机号码");
            ids.add(resume.getRphone());
            System.out.println("1");
        }
        if(resume.getSex() != null){
            xziduan1.add("性别");
            ids.add(String.valueOf(resume.getSex()));
            System.out.println("1");
        }
        if(resume.getRbirthday() != null){
            xziduan1.add("出生日期");
            ids.add((String.valueOf(resume.getRbirthday())));
            System.out.println("1");
        }
        if(!resume.getEducation().equals("")){
            xziduan1.add("学历");
            ids.add(resume.getEducation());
            System.out.println("1");
        }
        if(!resume.getWorkexp().equals("")){
            xziduan1.add("工作经验");
            ids.add(resume.getWorkexp());
        }
        if(!resume.getRnation().equals("")){
            xziduan1.add("民族");
            ids.add(resume.getRnation());
        }
        if(!resume.getNativeaddres().equals("")){
            xziduan1.add("籍贯");
            ids.add(resume.getNativeaddres());
        }
        if(!resume.getResidence().equals("")){
            xziduan1.add("户籍地址");
            ids.add(resume.getResidence());
        }
        if(!resume.getMarriage().equals("")){
            xziduan1.add("婚姻状况");
            ids.add(resume.getMarriage());
        }
        if(!resume.getRemail().equals("")){

            xziduan1.add("邮箱地址");
            ids.add(resume.getRemail());
        }
        if(!resume.getRwechat().equals("")){

            xziduan1.add("微信");
            ids.add(resume.getRwechat());
        }
        if(!resume.getRqq().equals("")){

            xziduan1.add("QQ");
            ids.add(resume.getRqq());
        }
        if(!resume.getIndustry().equals("")){

            xziduan1.add("期望行业");
            ids.add(resume.getIndustry());
        }
        if(!resume.getRposition().equals("")){

            xziduan1.add("期望职位");
            ids.add(resume.getRposition());
        }
        if(!resume.getRsalary().equals("")){

            xziduan1.add("期望年薪");
            ids.add(resume.getRsalary());
        }
        if(!resume.getWorkaddress().equals("")){

            xziduan1.add("期望工作地");
            ids.add(resume.getWorkaddress());
        }
        Integer rid = resume.getRid();
        for(int i = 0;i<ids.size();i++){
            Date date = new Date();
            Instant instant = date.toInstant();
            ZoneId zoneId = ZoneId.systemDefault();
            LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();

            String xin = ids.get(i);
            String xziduan = xziduan1.get(i);
            mapper.caozuo(rid,xin,xziduan,localDateTime);
        }
        return true;
    }

    @Override
    public List<Caozuo> findCao(Integer rid) {

        return mapper.findCao(rid);
    }

}
